<!-- 
此组件初始化时不会自动加载数据，请在mounted中 this.$refs.[].initData()
如果放在dialog里面的吗，请在dialog的open事件中用this.$nextTick进行加载
 -->
<template>
  <div>
    <list
      id-key="id"
      ref="list"
      unit="客户"
      :disabled="disabled"
      show-checkbox
      :query-params="queryParams"
      :expand-query="expandQuery"
      :show-summary="showSummary"
      page
      :get-page-list-func="api.getExamineStatusExceptionList"
    >
      <template #toolbar-left>
        <el-tooltip content="将新ICP系统客户代码同步到旧ICP，并新增一条审批通过的记录">
          <el-button
            type="primary"
            @click="repair"
            :loading="repairLoading"
          >修复状态</el-button>
        </el-tooltip>
        <slot name="toolbar-left"></slot>
      </template>
      <template #query>
        <!-- <el-form-item label="ID">
          <el-input v-model.trim="queryParams.id" clearable></el-input>
        </el-form-item> -->
        <div>
          <el-form-item label="客户名称">
            <el-input
              v-model.trim="queryParams.name"
              placeholder="客户原始名称"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="客户代码">
            <el-input
              v-model.trim="queryParams.code"
              placeholder="客户代码"
              clearable
            ></el-input>
          </el-form-item>
        </div>
        <div>
        </div>
      </template>
      <template #column>
        <!-- <el-table-column
          prop="status"
          width="90"
          label="发票状态"
          align="center"
        >
          <template #default="{ row }">
            <el-tooltip :content="row.nuoNuoMessage" :disabled="row.status!=6">
              <el-tag :type="getStatusType(row.status)">{{
                row.statusText
              }}</el-tag></el-tooltip
            >
          </template>
        </el-table-column> -->
        <el-table-column
          prop="name"
          min-width="150"
          label="客户名称"
          show-overflow-tooltip
        >
          <template #default="{row}">
            <span
              class="c-link"
              @click="openDetail(row.id)"
            >{{row.name}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="code"
          width="130"
          label="客户代码"
          show-overflow-tooltip
        />
        <el-table-column
          prop="examineState"
          width="100"
          label="审批状态"
          show-overflow-tooltip
        >
          <template #default="{ row }">
            {{ row.examineStateName }}
          </template>
        </el-table-column>
        <el-table-column
          prop="examineTime"
          width="120"
          label="审批时间"
          sortable="custom"
        >
          <template v-slot="{ row }">
            <span>{{ row.examineTime | toShortDatetimeString }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="code"
          width="100"
          label="旧ICP客户代码"
          show-overflow-tooltip
        />
        <el-table-column
          prop="oldIcpExamineState"
          width="100"
          label="旧ICP审批状态"
          show-overflow-tooltip
        >
          <template #default="{ row }">
            {{ row.oldIcpExamineStateName }}
          </template>
        </el-table-column>
        <!-- slot[column] -->
        <slot name="column"></slot>
        <!--/ slot[column]-->
      </template>
    </list>
    <detail-dialog
      ref="detailDialog"
      :in-dialog="inDialog"
    />
  </div>
</template>
<script>
import listMixin from "@/mixins/list";
import list from "@/components/common/list";
import detailDialog from "@/components/crm/customer/detailDialog";
import api from "@/api/crm/customer";
export default {
  mixins: [listMixin],
  components: {
    list,
    detailDialog,
  },
  props: {},
  data() {
    return {
      //查询条件字段
      queryParams: {
        invoiceNo: "",
        invoiceCode: "",
        serialNo: "",
        buyerTitleName: "",
        sellerTitleName: "",
        statuses: [],
      },
      api,
      repairLoading: false
    };
  },
  methods: {
    getStatusType(status) {
      var text = "";
      switch (status) {
        case 0:
          text = "info";
          break;
        case 1:
          text = "";
          break;
        case 2:
          //作废
          text = "info";
          break;
        case 3:
          //冲红
          text = "warning";
          break;
        case 6:
          text = "danger";
          break;
      }
      return text;
    },
    openDetail(id) {
      this.$refs.detailDialog.openDetail(id);
    },
    repair() {
      var rows = this.$refs.list.getCheckedRows();
      let message = "确定修复将选中的客户审批状态吗？";
      let postData;
      if (rows && rows.length > 0) {
        postData = { ids: rows.map((item) => item.id) };
      } else {
        message = "你确定将把列表全部数据进行修复审批状态吗"
        postData = this.$refs.list.tempQueryParams;
      }

      this.$confirm(message, "提示", {
        type: "warning",
      })
        .then(() => {
          this.$refs.list.loading(true);
          this.repairLoading = true;
          api.repairExamineStatus(postData).then((res) => {
            if (res.code != 0) {
              this.$refs.list.loading(false);
              this.repairLoading = false;
              return;
            }
            this.$refs.list.reload().then(() => {
              this.repairLoading = false;
            });
          });
        })
        .catch((e) => {
          console.log(e);
        });
    },
  },
};
</script>